const Mock = require('mockjs')
const users = {
	introduction: 'I am a super administrator',
	avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif',
	name: 'Admin',
	departmentName: '会计',
	email: '959814898@qq.com',
	phoneNumber: '13982104607'
}

const userInfo = Mock.mock({
	"curPage|1-10": 10,
	"pageSize": 10,
	"total": 10,
	'userInfos|10': [{
		id: '@id',
		userName: '@cname',
		phoneNumber: '@integer(10000000000,99999999999)',
		eMail: '@email',
		'role|1-4': ["admin", "admin1", "admin2"],
		creatTime: '@datetime',
		updateTime: '@datetime',
	}]
})


module.exports = [{
		url: '/xue-admin/user/login',
		type: 'post',
		response: config => {
			const {
				username
			} = config.body
			const token = "admin"

			if (!token) {
				return {
					code: 60204,
					message: 'Account and password are incorrect.'
				}
			}

			return {
				code: 200,
				data: token
			}
		}
	},

	// get user info
	{
		url: '/xue-admin/user/info\.*',
		type: 'get',
		response: config => {
			const info = users

			// mock error
			if (!info) {
				return {
					code: 50008,
					message: 'Login failed, unable to get user details.'
				}
			}

			return {
				code: 200,
				data: info
			}
		}
	},

	// user logout
	{
		url: '/vue-admin-template/user/logout',
		type: 'post',
		response: _ => {
			return {
				code: 200,
				data: 'success'
			}
		}
	},
	{
		url: '/xue-admin/user/department/\.*/info\.*',
		type: 'get',
		response: config => {
			return {
				code: 200,
				data: userInfo
			}
		}
	}


]
